package cn.stylefeng.guns.modular.technology.controller;

import cn.stylefeng.roses.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.mapper.EntityWrapper;

import org.springframework.ui.Model;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.PathVariable;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;

import cn.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;

import cn.stylefeng.guns.modular.system.model.Medicaltype;
import cn.stylefeng.guns.modular.system.model.Technologytype;
import cn.stylefeng.guns.modular.technology.service.ITechnologytypeService;

/**
 * 科技期刊控制器
 *
 * @author fengshuonan
 * @Date 2020-06-21 00:48:09
 */
@Controller
@RequestMapping("/technologytype")
public class TechnologytypeController extends BaseController {

    private String PREFIX = "/technology/technologytype/";

    @Autowired
    private ITechnologytypeService technologytypeService;

    /**
     * 跳转到科技期刊首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "technologytype.html";
    }

    /**
     * 跳转到添加科技期刊
     */
    @RequestMapping("/technologytype_add")
    public String technologytypeAdd() {
        return PREFIX + "technologytype_add.html";
    }

    /**
     * 跳转到修改科技期刊
     */
    @RequestMapping("/technologytype_update/{technologytypeId}")
    public String technologytypeUpdate(@PathVariable Integer technologytypeId, Model model) {
        Technologytype technologytype = technologytypeService.selectById(technologytypeId);
        model.addAttribute("item",technologytype);
        LogObjectHolder.me().set(technologytype);
        return PREFIX + "technologytype_edit.html";
    }

    /**
     * 获取科技期刊列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
    	EntityWrapper<Technologytype> wrapper = new EntityWrapper<Technologytype>();
    	wrapper.like("goods_name", condition).or()
    	.like("id", condition);
        return technologytypeService.selectList(wrapper);
    }

    /**
     * 新增科技期刊
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(Technologytype technologytype) {
        technologytypeService.insert(technologytype);
        return SUCCESS_TIP;
    }

    /**
     * 删除科技期刊
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer technologytypeId) {
        technologytypeService.deleteById(technologytypeId);
        return SUCCESS_TIP;
    }

    /**
     * 修改科技期刊
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(Technologytype technologytype) {
        technologytypeService.updateById(technologytype);
        return SUCCESS_TIP;
    }

    /**
     * 科技期刊详情
     */
    @RequestMapping(value = "/detail/{technologytypeId}")
    @ResponseBody
    public Object detail(@PathVariable("technologytypeId") Integer technologytypeId) {
        return technologytypeService.selectById(technologytypeId);
    }
    
    
    @InitBinder
   	public void initBinder(WebDataBinder binder) {
   	    DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
   	    binder.registerCustomEditor(Date.class, new CustomDateEditor(sdf, true));        
   	}
}
